//
//  CellForSearchUsers.m
//  ProjectA
//
//  Created by dllo on 16/2/29.
//  Copyright © 2016年 刘旺辉. All rights reserved.
//

#import "CellForSearchUsers.h"
#import <UIImageView+WebCache.h>
#import "ModelForSearchUsers.h"
#import "AppMacro.h"
@interface CellForSearchUsers ()

@property (nonatomic, strong) UIImageView *imageViewPhoto;
@end

@implementation CellForSearchUsers
- (void)dealloc {
    
    [_name release];
    [_imageViewPhoto release];
    [super dealloc];
    
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.imageViewPhoto = [[UIImageView alloc] init];
        [self.contentView addSubview:self.imageViewPhoto];
        [_imageViewPhoto release];
        
        self.name = [[UILabel alloc] init];
        [self.contentView addSubview:self.name];
        [_name release];
        
    }
    return self;
}
- (void)layoutSubviews {
    
    [super layoutSubviews];
    self.imageViewPhoto.frame = CGRectMake(10, 5, self.bounds.size.height - 10, self.bounds.size.height - 10);
    self.imageViewPhoto.layer.cornerRadius = self.imageViewPhoto.frame.size.width / 2.f;
    self.imageViewPhoto.layer.masksToBounds = YES;
    
    self.name.frame = CGRectMake(10 + self.imageViewPhoto.frame.size.width + 10, 5, self.bounds.size.width - 50, self.bounds.size.height - 10);

}
- (void)passData:(ModelForSearchUsers *)model withSearch:(NSString *)search {
    
    [self.imageViewPhoto sd_setImageWithURL:[NSURL URLWithString:model.avatar_m] placeholderImage:[UIImage imageNamed:@"iconfont-touxiang"]];
    
    [UIView setColorWithLabelText:self.name nightColor:L_COLOR_WHITE dayColor:L_COLOR_BLACK];
    
    NSMutableAttributedString *attributedStr = [[NSMutableAttributedString alloc] initWithString:model.name];
    [attributedStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:[model.name rangeOfString:search]];
    self.name.attributedText = attributedStr;
    
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
